unit uFlatSB;

{.$DEFINE Static}
{$DEFINE Dynamic}

{$IFnDEF Static}
  {$IFnDEF Dynamic}
    ' You must define one of $STATIC or $DYNAMIC
  {$ENDIF}
{$ENDIF}

{$IFDEF Static}
  {$IFDEF Dynamic}
    ' You can''t define both $STATIC AND $DYNAMIC
  {$ENDIF}
{$ENDIF}

interface

Uses Windows;

Const WSB_PROP_CYVSCROLL  = $00000001;
Const WSB_PROP_CXHSCROLL  = $00000002;
Const WSB_PROP_CYHSCROLL  = $00000004;
Const WSB_PROP_CXVSCROLL  = $00000008;
Const WSB_PROP_CXHTHUMB   = $00000010;
Const WSB_PROP_CYVTHUMB   = $00000020;
Const WSB_PROP_VBKGCOLOR  = $00000040;
Const WSB_PROP_HBKGCOLOR  = $00000080;
Const WSB_PROP_VSTYLE     = $00000100;
Const WSB_PROP_HSTYLE     = $00000200;
Const WSB_PROP_WINSTYLE   = $00000400;
Const WSB_PROP_PALETTE    = $00000800;
Const WSB_PROP_MASK       = $00000FFF;
Const FSB_FLAT_MODE       = 2;
Const FSB_ENCARTA_MODE    = 1;
Const FSB_REGULAR_MODE    = 0;

Const COMCTL32DLL = 'COMCTL32.DLL';

{$IFDEF STATIC}
Function InitializeFlatSB( aWindow : hWND ) : Boolean; stdcall; external COMCTL32DLL;
Function UninitializeFlatSB( aWindow : hWND ) : Boolean; stdcall; external COMCTL32DLL;

Function FlatSB_EnableScrollBar( aWindow : hWND; aSBFlags : LongInt; aArrows : LongInt ) : Boolean; stdcall; external COMCTL32DLL;

Function FlatSB_GetScrollInfo( aWindow : hWND; aBar : LongInt; var rInfo : TScrollInfo ) : Boolean; stdcall; external COMCTL32DLL;
Function FlatSB_GetScrollPos( aWindow : hWND; aBar : LongInt ) : Integer; stdcall; external COMCTL32DLL;
Function FlatSB_GetScrollProp( aWindow : hWND; aIndex : LongInt; var rValue : LongInt ) : Boolean; stdcall; external COMCTL32DLL;
Function FlatSB_GetScrollRange( aWindow : hWND; aIndex : LongInt; var rRangeMin : LongInt; var rRangeMax : LongInt ) : Boolean; stdcall; external COMCTL32DLL;

Function FlatSB_SetScrollInfo( aWindow : hWND; aBar : LongInt; const aInfo : TScrollInfo; aRedraw : Boolean ) : Integer; stdcall; external COMCTL32DLL;
Function FlatSB_SetScrollPos( aWindow : hWND; aBar : LongInt; aPos : LongInt; aRedraw : Boolean ) : Boolean; stdcall; external COMCTL32DLL;
Function FlatSB_SetScrollProp( aWindow : hWND; aIndex : LongInt; aValue : LongInt; aRedraw : Boolean ) : Boolean; stdcall; external COMCTL32DLL;
Function FlatSB_SetScrollRange( aWindow : hWND; aIndex : LongInt; aRangeMin : LongInt; aRangeMax : LongInt; aRedraw : Boolean ) : Boolean; stdcall; external COMCTL32DLL;

Function FlatSB_ShowScrollBar( aWindow : hWND; aBar : LongInt; aShow : Bool ) : Boolean; stdcall; external COMCTL32DLL;
{$ENDIF}

{$IFDEF DYNAMIC}
Type fsbHandleProc = Function( aWindow : hWND ) : Boolean; stdcall;
     fsbEnableSBProc = Function( aWindow : hWND; aSBFlags : LongInt; aArrows : LongInt ) : Boolean; stdcall;
     fsbGetScrollInfo = Function( aWindow : hWND; aBar : LongInt; var rInfo : TScrollInfo ) : Boolean; stdcall;
     fsbGetScrollPos = Function( aWindow : hWND; aBar : LongInt ) : Integer; stdcall;
     fsbGetScrollProp = Function( aWindow : hWND; aIndex : LongInt; var rValue : LongInt ) : Boolean; stdcall;
     fsbGetScrollRange = Function( aWindow : hWND; aIndex : LongInt; var rRangeMin : LongInt; var rRangeMax : LongInt ) : Boolean; stdcall;
     fsbSetScrollInfo = Function( aWindow : hWND; aBar : LongInt; const aInfo : TScrollInfo; aRedraw : Boolean ) : Integer; stdcall;
     fsbSetScrollPos = Function( aWindow : hWND; aBar : LongInt; aPos : LongInt; aRedraw : Boolean ) : Boolean; stdcall;
     fsbSetScrollProp = Function( aWindow : hWND; aIndex : LongInt; aValue : LongInt; aRedraw : Boolean ) : Boolean; stdcall;
     fsbSetScrollRang = Function( aWindow : hWND; aIndex : LongInt; aRangeMin : LongInt; aRangeMax : LongInt; aRedraw : Boolean ) : Boolean; stdcall;
     fsbShowScrollBar = Function( aWindow : hWND; aBar : LongInt; aShow : Bool ) : Boolean; stdcall;

Var InitializeFlatSB : fsbHandleProc;
    UninitializeFlatSB : fsbHandleProc;

    FlatSB_EnableScrollBar : fsbEnableSBProc;

    FlatSB_GetScrollInfo : fsbGetScrollInfo;
    FlatSB_GetScrollPos  : fsbGetScrollPos;
    FlatSB_GetScrollProp : fsbGetScrollProp;
    FlatSB_GetScrollRange : fsbGetScrollRange;
    FlatSB_SetScrollInfo : fsbSetScrollInfo;
    FlatSB_SetScrollPos  : fsbSetScrollPos;
    FlatSB_SetScrollProp : fsbSetScrollProp;
    FlatSB_SetScrollRange : fsbSetScrollRang;
    FlatSB_ShowScrollBar : fsbShowScrollBar;
{$ENDIF}

implementation

Function _InitializeFlatSB( aWindow : hWND ) : Boolean; stdcall;
Begin
  Result := True;
End;

Function _UninitializeFlatSB( aWindow : hWND ) : Boolean; stdcall;
Begin
  Result := True;
End;

Function _GetScrollProp( aWindow : hWND; aIndex : LongInt; var rValue : LongInt ) : Boolean; stdcall; export;
Begin
  rValue := 0;
  Result := True;
End;

Function _SetScrollProp( aWindow : hWND; aIndex : LongInt; aValue : LongInt; aRedraw : Boolean ) : Boolean; stdcall; export;
Begin
  Result := True;
End;

{$IFDEF DYNAMIC}
var hCOMCTL : HModule;
{$ENDIF}

initialization
{$IFDEF DYNAMIC}
  hCOMCTL := LoadLibrary( COMCTL32DLL );
  If hCOMCTL <> 0
    then
      Begin
        InitializeFlatSB := GetProcAddress( hCOMCTL, 'InitializeFlatSB' );
        UninitializeFlatSB := GetProcAddress( hCOMCTL, 'UninitializeFlatSB' );

        FlatSB_EnableScrollBar := GetProcAddress( hCOMCTL, 'FlatSB_EnableScrollbar' );

        FlatSB_GetScrollInfo := GetProcAddress( hCOMCTL, 'FlatSB_GetScrollInfo' );
        FlatSB_GetScrollPos  := GetProcAddress( hCOMCTL, 'FlatSB_GetScrollPos' );
        FlatSB_GetScrollProp := GetProcAddress( hCOMCTL, 'FlatSB_GetScrollProp' );
        FlatSB_GetScrollRange := GetProcAddress( hCOMCTL, 'FlatSB_GetScrollRang' );
        FlatSB_SetScrollInfo := GetProcAddress( hCOMCTL, 'FlatSB_SetScrollInfo' );
        FlatSB_SetScrollPos  := GetProcAddress( hCOMCTL, 'FlatSB_SetScrollPos' );
        FlatSB_SetScrollProp := GetProcAddress( hCOMCTL, 'FlatSB_SetScrollProp' );
        FlatSB_SetScrollRange := GetProcAddress( hCOMCTL, 'FlatSB_SetScrollRang' );
        FlatSB_ShowScrollBar := GetProcAddress( hCOMCTL, 'FlatSB_ShowScrollBar' );
      End
    else
      Begin
        InitializeFlatSB := @_InitializeFlatSB;
        UninitializeFlatSB := @_UninitializeFlatSB;

        FlatSB_EnableScrollBar := @EnableScrollbar;
        FlatSB_GetScrollInfo := @GetScrollInfo;
        FlatSB_GetScrollPos  := @GetScrollPos;
        FlatSB_GetScrollProp := @_GetScrollProp;
        FlatSB_GetScrollRange := @GetScrollRange;
        FlatSB_SetScrollInfo := @SetScrollInfo;
        FlatSB_SetScrollPos  := @SetScrollPos;
        FlatSB_SetScrollProp := @_SetScrollProp;
        FlatSB_SetScrollRange := @SetScrollRange;
        FlatSB_ShowScrollBar := @ShowScrollBar;
      End;
{$ENDIF}
finalization
  If hCOMCTL <> 0
    then FreeLibrary( hCOMCTL );
end.
